package stud.mpgame.server.game;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;

import org.slf4j.LoggerFactory;

import stud.mpgame.network.Message;
import stud.mpgame.network.UserObject;
import stud.mpgame.network.util.MessageUtils;

import stud.mpgame.snapshot.ICommand;
import stud.mpgame.snapshot.ISnapshot;

/**
 * @author f.pavel91@gmail.com
 * @version 1.0
 */
public class LoginCommand extends UserObject implements ICommand {

    private int time;
    private IoSession session;
    private String nickname;
    private int userID;

    private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger(LoginCommand.class);

    @Override
    public void readExternal(IoBuffer buffer, Message owner) {
        nickname = MessageUtils.bytesToStr(buffer);
        userID = buffer.getInt();
    }

    public void setTime(int time) {
        this.time = time;
    }

    public void setSession(IoSession session) {
        this.session = session;
    }

    public int getTime() {
        return time;
    }

    public void apply(ISnapshot snapshot) {
        LOGGER.info("Player connected!");
    }

    @Override
    public String toString() {
        String result = "\n";
        result += "nickname: " + nickname + "\n";
        result += "UserID: " + userID + "\n";
        return result;
    }

}
